%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Version 11/10/2012 - Marcelo Sant'Anna
% 
% kernel.m is the kernel used in estimation. The kernel is chosen by opt 
%
%
% [k] = kernel(u,opt)
% 
% inputs: u       - Can be a matrix n x m.
%         opt     - options for the kernel.
%                   opt.k = kernel function
%
% output: k       
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function [k] = kernel(u,opt)

k = zeros(size(u));

if opt.k == 1
    % Epanechnikov kernel (Li and Racine, page 35):
        A = (u.^2<=5);
        k(A) = (3/(4*sqrt(5)))*(1-.2*u(A).^2);
        k(~A)= 0;
elseif opt.k == 2
    % Normal density kernel
    k = normpdf(u,0,1);
elseif opt.k == 3
    % Triweight kernel:
    A = (abs(u)<1);
    c = (35/34);
    k(A) = c*(1-u(A).^2).^3;
else
    disp('Unspecified kernel')
end

end